/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package se.bth.ke.searchindexer;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
/**
 *
 * @author nico
 */
public class HibernateMassIndex {

    public static void main(String[] args) throws Exception {
        try {
            EntityManagerFactory factory = Persistence.createEntityManagerFactory("se.bth.ke.firstfriend.web-PU");
            EntityManager em = factory.createEntityManager();

            EntityTransaction tx = em.getTransaction();
            tx.begin();

            try {
                FullTextEntityManager ftem = Search.getFullTextEntityManager(em);
                ftem.createIndexer().startAndWait();
            } catch (Exception e) {
                tx.rollback();
            }
            tx.commit();
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}
